#!/bin/bash
# echo the call so we can see what's going on
echo "$0 $1 $2 $3 $4 $5 $6"

# Check syntax
if [ "$1" = "" ]; then
	echo "$0 called without number of histogram for which absorption should be varied!"
	exit 0
fi

if [ "$2" = "" ]; then
	echo "$0 called without absorption function number!"
	exit 0
fi

if [ "$3" = "" ]; then
	echo "$0 called without refinement flag!"
	exit 0
fi

# Change the flags
echo "k l o a" > temp.txt
echo "h $1" >> temp.txt
echo "t $2" >> temp.txt
echo "g $1 $1 $3" >> temp.txt
if [ "$4" = "" ]; then
	# we are done, no damping
	echo "No damping provided"
else 
	echo "d $4" >> temp.txt
fi
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt

expedt `cat GSAS_EXP` < temp.txt

# Test the EXP file
echo "Changed absorption refinement flag for histogram $1 to $3 (function $2)" >> temp.tex
if [ "$4" = "" ]; then
	echo " (with damping unchanged).\newline" >> temp.tex
else 
	echo " (with damping set to $4).\newline" >> temp.tex
fi